package com.midian.action.mc.permission;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import com.midian.action.mc.common.AjaxAction;
import com.midian.common.annotation.FunctionAnnotationOverride;
import com.midian.common.exception.BizException;
import com.midian.common.system.SysStatic;
import com.midian.model.permission.Auth;
import com.midian.service.permission.IAuthService;

/**
 * 权限Action
 * @author Mengfh
 *
 */
@Scope("prototype")
@Controller("authAction")
@FunctionAnnotationOverride(isAction = true, auth = "权限管理")
public class AuthAction extends AjaxAction<Auth> {
	
	private static final long serialVersionUID = 548793811982341927L;
	/**权限对象*/
	private Auth entity;
	/**权限列表*/
	private List<Auth> rows;
	/**权限业务*/
	private IAuthService authService;

	public Auth getEntity() {
		return entity;
	}

	public void setEntity(Auth entity) {
		this.entity = entity;
	}
	

	@Override
	protected Auth dytEntity() {
		if(this.entity == null) {
			this.entity = new Auth();
		}
		return getEntity();
	}

	@Override
	protected void dyEntity(Auth t) {
		setEntity(t);
	}

	public List<Auth> getRows() {
		return rows;
	}

	public void setRows(List<Auth> rows) {
		this.rows = rows;
	}

	@Resource(name = "authService")
	public void setAuthService(IAuthService authService) {
		this.service = authService;
		this.authService = authService;
	}

	@Override
	public String saveInfo() {
		//检测是否已存在权限
		try {
			if(this.authService.isExistAuth(this.entity.getKeyName())) {
				throw new BizException("对不起，权限已添加，请重新设置！");
			}
			super.saveInfo();
		} catch (BizException e) {
			getError(e);
		}
		return SAVEINFO;
	}

	@Override
	public String showList() {
		if(this.entity == null) {
			this.entity = new Auth();
		}
		//获取全部权限
		this.entity.setDelFlag(null);
		return super.showList();
	}

	@Override
	public String showListWithoutPager() {
		if(this.entity == null) {
			this.entity = new Auth();
		}
		//获取没被禁用的权限
		this.entity.setDelFlag(SysStatic.NORMALDELFLAG);
		return super.showListWithoutPager();
	}
}
